package com.orange.lockscreensettings.wallpaper;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.os.Bundle;

import com.orange.lockscreensettings.R;
import com.orange.lockscreensettings.common.SettingsUtils;

public class ChooserActivity extends Activity implements OnDismissListener {

	public static final String		TAG						= "ChooserActivity";

	private static final int		DIALOG_LIST				= 0;
	public static final String		ACTION_SET_WALLPAPER	= "com.orange.lockscreen.action.SET_WALLPAPER";

	private WallpaperPickerAdapter	mAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mAdapter = new WallpaperPickerAdapter(this);
		showDialog(DIALOG_LIST);
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		Dialog dialog = null;
		switch (id) {
		case DIALOG_LIST:
			dialog = new AlertDialog.Builder(this)
					.setTitle(getString(R.string.title_choose_wallpaper))
					.setAdapter(mAdapter,
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									Intent intent = new Intent();
									intent.putExtra("id", which);
									intent.setAction(ACTION_SET_WALLPAPER);
									SettingsUtils
											.startActivityForResult(
													ChooserActivity.this,
													intent, which);
									dialog.dismiss();
								}
							}).create();
			dialog.setOnDismissListener(this);
			break;
		default:
			break;
		}
		return dialog;
	}

	@Override
	public void onDismiss(DialogInterface dialog) {
		finish();
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
		ChooserActivity.this.finish();
	}
}
